<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>供应商订舱业务管理</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var formSetting = {
        title: "查询订舱业务信息",
        module: 'query',
        numCount: 4,
        columns: [{
            name: "businessId",
            label: "业务编码"
        }, {
            name: "bookingState",
            label: "审核状态",
            type: "dropdown",
            dropdownType: "ajax",
            url: "../base/dropdown-bookingState",
            op: "eq",
            minLength: 0
        }, {
            name: "pi",
            label: "PI号"
        }, {
            name: "so",
            label: "SO号"
        }, {
            name: "creator",
            label: "下单操作人"
        }, {
            name: "confirmTime",
            label: "业务提交时间从",
            type: "date",
            op: "ge"
        }, {
            name: "confirmTime",
            label: "到",
            type: "date",
            op: "le"
        }],
        buttons: {
            custom: [
                {
                    id: "updatebtn0",
                    value: "查看详细",
                    click: function () {
                        var id = $("#bookingsDataGrid").jqGrid("getGridParam",
                                                               "selrow");
                        if (id) {
// 							window.location.href="booking-bizView?id="+id;
                            window.location.href =
                                    "business-checkDetail?id=" + id
                                    + "&singleType=F&identification=list";
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
// 				{
// 					id : "reject",
// 					value : "驳回",
// 					click : function() {
// 						var id = $("#bookingsDataGrid").jqGrid("getGridParam","selrow");
// 						var rowDatas = $("#bookingsDataGrid").jqGrid('getRowData',id);
// 						var row = rowDatas["bookingState"];
// 						if(row == "草稿状态") {
// 							jw.dialog({
// 								iframe : '../business/rejectContent-reject?id='+id+"&type=3",
// 								title : "驳回",
// 								iframeFetchTitle : false,
// 								width : 500,
// 								height : 150
// 							});
// 						} else{
// 							jw.alert("请选择草稿状态业务的数据!");
// 						}
// 					}
// 				},
                {
                    id: "checkRejectContent",
                    value: "查看驳回",
                    click: function () {
                        var id = $("#bookingsDataGrid").jqGrid("getGridParam",
                                                               "selrow");
                        var rowDatas = $("#bookingsDataGrid").jqGrid('getRowData', id);
                        var row = rowDatas["bookingState"];
                        if (row == "驳回状态" || row == "草稿状态") {
                            //window.location.href="rejectContent-rejectList?id="+id;
                            jw.dialog({
                                          iframe: '../business/rejectContent-rejectList?id=' + id,
                                          title: "查看驳回",
                                          iframeFetchTitle: false,
                                          width: 800,
                                          height: 300
                                      });
                        } else {
                            jw.alert("请选择驳回状态和草稿状态业务的数据!");
                        }
                    }
                },
                {
                    id: "updatebtn00",
                    value: "修改业务",
                    click: function () {
                        var id = $("#bookingsDataGrid").jqGrid("getGridParam",
                                                               "selrow");
                        if (id) {
                            var ret = $("#bookingsDataGrid").jqGrid('getRowData', id);
                            var data = "id=" + ret.id;
                            $.ajax({
                                       url: "booking-checkBizModify",
                                       dataType: "json",
                                       data: data,
                                       success: function (data) {
                                           if (!data) {
                                               return;
                                           }
                                           var msg = data.msg ? $.parseJSON(data.msg) : "";
                                           if (msg.state == 1) {
                                               jw.confirm("确定要修改该业务?", function () {
                                                              window.location.href =
                                                                      "business-updateSingle?id=" + id
                                                                      + "&singleType=F";
                                                              //"booking-bizModify?booking.id="+ret.id;
                                                          },
                                                          function () {
                                                              return;
                                                          });
                                           }
                                           else if (msg !== undefined && msg != "" && msg.state
                                                                                      == 0) {
                                               jw.alert("只有处于草稿和驳回状态的业务才可以修改。");
                                           }
                                           else {
                                               jw.alert(msg.msg);
                                           }
                                       }
                                   });
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "delbtn",
                    value: "删除业务",
                    click: function () {
                        var selectedIds = $("#bookingsDataGrid").jqGrid("getGridParam", "selrow");
                        var rowDatas = $("#bookingsDataGrid").jqGrid('getRowData', selectedIds);
                        var row = rowDatas["bookingState"];
                        if (row == "草稿状态") {
                            if (confirm("确定要删除选择的项?")) {
                                var data = "id=" + selectedIds;
                                $.ajax({
                                           url: "booking-del",
                                           dataType: "json",
                                           data: data,
                                           cache: false,
                                           success: function (data) {
                                               var msg = $.parseJSON(data.msg);
                                               if (msg.state == "1") {
                                                   $("#bookingsDataGrid").jqGrid("setGridParam",
                                                                                 {
                                                                                     search: true
                                                                                     // 将jqGrid的search选项设为true
                                                                                 }).trigger(
                                                           "reloadGrid", [{
                                                               page: 1
                                                           }]);
                                                   jw.alert(msg.msg);
                                               } else {
                                                   jw.alert(msg.msg);

                                               }
                                           }
                                       });
                            }
                        } else {
                            jw.alert("请选择草稿状态业务的数据!");
                        }
                    }
                },
                {
                    id: "updatebtn1",
                    value: "提交业务",
                    click: function () {
                        var id = $("#bookingsDataGrid").jqGrid("getGridParam",
                                                               "selrow");
                        if (id) {
                            var ret = $("#bookingsDataGrid").jqGrid('getRowData', id);
                            var iddata = "id=" + ret.id;
                            $.ajax({
                                       url: "booking-checkBizConfirm",
                                       dataType: "json",
                                       data: iddata,
                                       success: function (data) {
                                           if (!data) {
                                               return;
                                           }
                                           var msg = data.msg ? $.parseJSON(data.msg) : "";
                                           if (msg.state == 1) {
                                               jw.confirm("确定要提交该业务?", function () {
                                                              $.ajax({
                                                                         url: "booking-bizConfirm",
                                                                         dataType: "json",
                                                                         data: iddata,
                                                                         success: function (data) {
                                                                             jw.alert(msg.msg);
                                                                             $("#bookingsDataGrid").jqGrid(
                                                                                     "setGridParam",
                                                                                     {
                                                                                         search: true
                                                                                         // 将jqGrid的search选项设为true
                                                                                     }).trigger("reloadGrid",
                                                                                                [{
                                                                                                    page: 1
                                                                                                }]);
                                                                         }
                                                                     });
                                                          },
                                                          function () {
                                                              return;
                                                          });
                                           }
                                           else if (msg !== undefined && msg != "" && msg.state
                                                                                      == 0) {
                                               jw.alert("只有处于草稿和驳回状态的业务才可以提交。");
                                           }
                                           else {
                                               jw.alert(msg.msg);
                                           }
                                       }
                                   });
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                }
            ]
        },
        grid: {
            id: "bookingsDataGrid",
            title: "查询结果",
            url: "booking-findList",
            //multiselect : true,
            /* postData : {
             "pid" : pid
             }, */
            colModel: [{
                index: "ID",
                name: "id",
                hidden: true
            }, {
                index: "businessId",
                name: "businessId",
                label: "业务编号"
            }, {
                index: "so",
                name: "so",
                label: "SO号"
            }, {
                index: "supNAME",
                name: "supCompany.name",
                label: "业务供应商"
            }, {
                index: "shipper",
                name: "shipper.company",
                label: "实际托运人",
                hidden: true
            }, {
                index: "shipDate",
                name: "shipDate",
                label: "船期要求"
// 				formatter:'date',
// 				formatoptions: {srcformat:'Y-m-d H:i:s',newformat:'Y-m-d'}
            }, {
                index: "price",
                name: "price",
                label: "合作价格"
            }, {
                index: "confirmTime",
                name: "confirmTime",
                label: "业务提交时间",
                formatter: 'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}
            }, {
                index: "operateState",
                name: "operateState",
                label: "业务操作进度",
                hidden: true
            }, {
                index: "validateState",
                name: "bookingState",
                label: "审核状态"
            }, {
                index: "creator",
                name: "creator",
                label: "下单操作人"
            }
                /* , {
                 index : "en",
                 name : "en",
                 label : "英文名"
                 }, {
                 index : "identifier",
                 name : "identifier",
                 label : "标识符"
                 }, {
                 index : "use_state",
                 name : "use_state",
                 label : "使用状态",
                 formatter : function(cellvalue, options, rowObject) {
                 if (cellvalue == "0") {
                 return "启用";
                 } else {
                 return "禁用";
                 }
                 }
                 }, {
                 index : "updateUser",
                 name : "updateUser",
                 label : "修改人"
                 }, {
                 index : "updateDate",
                 name : "updateDate",
                 label : "修改时间"
                 }  */],
            sortname: "businessId",
            sortorder: "desc",
            jsonReader: {
                root: "bookings"
            },
            loadComplete: function (data) {
                var ids = $("#bookingsDataGrid").getDataIDs();
                for (var i = 0; i < ids.length; i++) {
                    var arrayData = $("#bookingsDataGrid").getRowData(ids[i]);
// 					if(arrayData.bookingState=="已上传") {
                    if (arrayData.bookingState == "安排中") {
// 						$("#bookingsDataGrid").setCell(ids[i], "operateState", "<span style='cursor:pointer;' onclick=\"findBizState(\'" + i + "\', 'state', \'"+arrayData.id+"\');\"><font color='red'>点击查看</font><span>");
                        $("#bookingsDataGrid").setCell(ids[i], "bookingState",
                                                       "安排中 <span style='cursor:pointer;' onclick=\"findBizState(\'"
                                                       + i + "\', 'state', \'" + arrayData.id
                                                       + "\');\"><font color='red'>进度查询</font><span>");
                    }
                    else if (arrayData.bookingState == "已完成") {
// 						$("#bookingsDataGrid").setCell(ids[i], "operateState", "<span style='cursor:pointer;' onclick=\"findBizState(\'" + i + "\', 'state', \'"+arrayData.id+"\');\">点击查看<span>");
                        $("#bookingsDataGrid").setCell(ids[i], "bookingState",
                                                       "已完成 <span style='cursor:pointer;' onclick=\"findBizState(\'"
                                                       + i + "\', 'state', \'" + arrayData.id
                                                       + "\');\"><font color='red'>进度查询</font><span>");
                        //$("#declarationsDataGrid").setCell(ids[i], "operateState", "业务已完成");
                        $($("#" + arrayData.id).find("td")[7]).addClass("biz_state_finish");
                    }
                    else {
// 						$("#bookingsDataGrid").setCell(ids[i], "operateState", "业务未上传");
                        $("#bookingsDataGrid").setCell(ids[i], "operateState", "业务未安排");
                    }
                }
            },
            ondblClickRow: function () {
                var selectedRowId = $("#bookingsDataGrid").getGridParam("selrow");
                if (selectedRowId) {
                    var selectedRow = $("#bookingsDataGrid").getRowData(selectedRowId);
                    if (selectedRow.bookingState == "草稿状态") {
                        //selectedRow.busiId
                        location.href =
                                "business-updateSingle?id=" + selectedRow.id + "&singleType=F";
                    } else {
                        location.href =
                                "business-updateSingle?id=" + selectedRow.id
                                + "&singleType=F&identification=list";
                    }
                }
            }

        }
    };
    $(document).ready(function () {
        $("#bookingsDataTable").mrdForm(formSetting);
    });

    function setGridCell(i, name, value) {
        var ids = $("#declarationsDataGrid").getDataIDs();
        $("#declarationsDataGrid").setCell(ids[i], name, value);
    }

    function findBizResult(bizId) {
        jw.dialog({iframe: 'booking-findBizResult?id=' + bizId});
    }

    function findBizState(i, colName, bizId) {
        var data = "id=" + bizId;
// 		$.ajax({
// 			url : "booking-findBizState",
// 			cache: false,
// 			dataType : "json",
// 			data : data,
// 			success : function(data) {
// 				setGridCell(i, colName, data.msg);
// 			}
// 		});
// 		setGridCell(i, colName, "loadding...");
        findBizResult(bizId);
    }
</script>
<body>
<div id="bookingsDataTable"></div>
</body>
</html>
